package com.example.mp.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mp.entity.Dept;
import com.example.mp.entity.TUser;
import com.example.mp.service.ITUserService;
import com.example.mp.util.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ykg
 * @since 2022-12-28
 */
@RestController
@RequestMapping("/t_user")
public class TUserController {
    @Resource
    private ITUserService userService;
    /*
    * 查询，通用mapper*/
    @GetMapping
    public Result findAll(Integer current, Integer size, TUser user){
        //List<TUser> list=userService.list();
        Page page=new Page(current,size);
        QueryWrapper queryWrapper= new QueryWrapper();
        if (StringUtils.isNotBlank(user.getUsername())){
            queryWrapper.like("username",user.getUsername());
        }else if (StringUtils.isNotBlank(user.getSex())){
            queryWrapper.like("sex",user.getSex());
        }
        Page page1=userService.page(page,queryWrapper);
        return new Result(page1);
    }
/*
* 删除，根据id 进行删除，通用mapper
* */
    @DeleteMapping("{id}")
    public Result delBuId(@PathVariable Integer id){
        return  new Result(userService.removeById(id));
    }


    /*添加，和修改，通用mapper
    * */
    @PostMapping
    public Result addOrUpdate(TUser user){
        return new Result(userService.saveOrUpdate(user));
    }


}

